<template>
	<view class="status-bar"></view>
	<view class="con size29 color333">
		<view class="flex-ju-c mt20 bold color333 size35">消息</view>
		<view @click="navto('like')" class="flex-ju-b height122">
			<view class="flex-a-i posire">
				<view v-if="user.like_un_read" class="top0 left65 posiab wh20-20 bgf00 ra20"></view>
				<image mode="widthFix" class="image width81 mr20" src="/static/img/dianzan.png"></image>
				点赞和收藏
			</view>
			<view>
				<uni-icons type="right" color="#333" size="17"></uni-icons>
			</view>
		</view>
		<view @click="navto('comment')" class="flex-ju-b height122">
			<view class="flex-a-i posire">
				<view v-if="user.word_un_read" class="top0 left65 posiab wh20-20 bgf00 ra20"></view>
				<image mode="widthFix" class="image width81 mr20" src="/static/img/pinglun.png"></image>
				评论和@
			</view>
			<view>
				<uni-icons type="right" color="#333" size="17"></uni-icons>
			</view>
		</view>
		<view @click="navto('follow')" class="flex-ju-b height122">
			<view class="flex-a-i posire">
				<view v-if="user.care_un_read" class="top0 left65 posiab wh20-20 bgf00 ra20"></view>
				<image mode="widthFix" class="image width81 mr20" src="/static/img/xinzeng.png"></image>
				新增关注
			</view>
			<view>
				<uni-icons type="right" color="#333" size="17"></uni-icons>
			</view>
		</view>
		<view @click="navto('getmsg')" class="flex-ju-b height122">
			<view class="flex-a-i">
				<image mode="widthFix" class="image width81 mr20" src="/static/img/xiaoxi.png"></image>
				<view>
					<view>消息通知</view>
					<view class="size26 color999 mt5">周末一起去打球吧</view>
				</view>
			</view>
			<view>
				<uni-icons type="right" color="#333" size="17"></uni-icons>
			</view>
		</view>

		 <im-conversation-list ref="uni-im-conversation-list" @clickItem="toChat" @change="conversationList = $event"
		 			id="conversation-list-box"></im-conversation-list>
	</view>
</template>

<script>
	import uniIm from '@/uni_modules/uni-im/sdk/index.js';
	export default {
		data() {
			return {
				user: {},
				conversationList: [],
				options: [{
						text: '聊天置顶',
						style: {
							backgroundColor: '#FF8A4C'
						}
					},
					{
						text: '删除',
						style: {
							backgroundColor: '#FF3B30'
						}
					}
				],
			}
		},
		async onLoad() {
			this.http('/api/msg_list', {}).then(res => {

			})
			
			await uniIm.conversation.loadMore()
			
			 
		},
		onShow() {
			this.user = uni.getStorageSync('user')
			this.getmsgs()
			
			 
		},
		methods: {
			toChat(item) {
				uni.navigateTo({
					url: '/uni_modules/uni-im/pages/chat/chat?conversation_id=' + item.id
				});
			},
			getmsgs(){
				this.conversationList = []
				var list = uni.getStorageSync('msg')
				if(list.length){
					list.map(item=>{
						if(item.unid == this.user.uid){
							item.list.map(items=>{
								var dd = items.data.pop()
								dd.allunread = items.allunread
								this.conversationList.unshift(dd)
							})
						}
					})
				}
			},
			paginate(array, page_size, page_number) {
			    // 计算分页开始的索引
			    const start = (page_number - 1) * page_size;
			    // 计算分页结束的索引
			    const end = page_number * page_size;
			    // 返回分页后的数组
			    return array.slice(start, end);
			},
			  formatTime(timestamp) {
			    
			   // 将时间戳转换为日期对象
			   var date = new Date(timestamp);
			    
			   // 获取年、月、日、小时、分钟、秒
			   var year = date.getFullYear();
			   var month = date.getMonth() + 1; // 月份是从0开始的
			   var day = date.getDate();
			   var hour = date.getHours();
			   var minute = date.getMinutes();
			   var second = date.getSeconds();
			    
			   // 格式化日期时间
			   month = month < 10 ? '0' + month : month;
			   day = day < 10 ? '0' + day : day;
			   hour = hour < 10 ? '0' + hour : hour;
			   minute = minute < 10 ? '0' + minute : minute;
			   second = second < 10 ? '0' + second : second;
			    
			   // 如果需要判断是否为当天，可以创建一个新的Date对象，并与当前日期对比
			   var today = new Date();
			   if (year == today.getFullYear() && month == (today.getMonth() + 1) && day == today.getDate()) {
			       // 是当天
				   return hour + ':' + minute
			   } else {
			       // 不是当天
				   return year + '-' + month + '-' + day + ' ' + hour + ':' + minute
			   }
			 },
			
			clickItem(item) {
				var url
				// if(item.payload.type == "self"){
				// 	url = JSON.stringify(item.payload.user)
				// }else{
				// 	url = JSON.stringify(item.payload.tuser)
				// }
				// url = JSON.stringify(item.payload.tuser)
				
				
				// if(item.payload.type == "self"){
				// 	if(this.user.uid == item.payload.tuser.uid){
				// 		url = JSON.stringify(item.payload.user)
				// 	}else{
				// 		url = JSON.stringify(item.payload.tuser)
				// 	}
				// }else{
					
				// }
				
				url = JSON.stringify(item.payload.tuser)
				uni.navigateTo({
					url:"message?userinfo="+url
				})
			}
		}
	}
</script>

<style>

</style>